<?php

namespace common\widgets\grid;

/**
 * DataColumn is the default column type for the [[GridView]] widget.
 *
 * @author emhome <emhome@163.com>
 * @since 2.0
 */
class DataColumn extends \yii\grid\DataColumn {

    /**
     * @var boolean 是否使用绝对时间戳
     */
    public $absoluteTimestamp = false;

    /**
     * {@inheritdoc}
     */
    protected function renderDataCellContent($model, $key, $index) {
        if ($this->content === null) {
            $value = $this->getDataCellValue($model, $key, $index);
            if ($this->format === 'datetime' || $this->format === 'date') {
                if ($this->absoluteTimestamp === false && !$value) {
                    return $this->grid->emptyCell;
                }
            }
            return $this->grid->formatter->format($value, $this->format);
        }
        return parent::renderDataCellContent($model, $key, $index);
    }

}
